package edu.ustb.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.ustb.domain.Address;
import edu.ustb.domain.Cart;
import edu.ustb.domain.Goods;
import edu.ustb.domain.User;
import edu.ustb.service.AddressService;
import edu.ustb.service.AddressServiceImpl;
import edu.ustb.service.CartSearchService;
import edu.ustb.service.CartSearchServiceImpl;
import edu.ustb.utils.MybatisUtil;

@WebServlet("/cart.action")
public class CartSearchController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//设置编码格式
		request.setCharacterEncoding("utf-8");
		
		User user = (User) request.getSession().getAttribute("user");
		int userId=user.getUserId();
		CartSearchService cartSearchService = new CartSearchServiceImpl();	
		List <Cart> cartList1 = cartSearchService.isSearchCart(userId);
		List <Goods> goodsList1 = cartSearchService.isSearchGoodsByCart(userId);
		
		
		//if (cartList1 !=null && cartList1.size()>0){
			request.setAttribute("cartList1", cartList1);
			request.setAttribute("goodsList1", goodsList1);
			
			//跳转界面，展示数据
			request.getRequestDispatcher("/Cart.jsp").forward(request, response);
			MybatisUtil.close();
//		}else if (cartList1==null){
//			MybatisUtil.rollback();
//		}		
	}
}